class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head)
    {
        if (head == nullptr || head->next == nullptr)
            return head;
        ListNode* slow, * fast;
        slow = head;
        fast = head->next;
        while (fast)
        {
            if (slow->val == fast->val)
            {
                fast = fast->next;
                slow->next = fast;
            }
            else
            {
                slow = slow->next;
                fast = fast->next;
            }
        }
        return head;
    }
};